package avicit.im.lantop.basic.archiveRecommendFolder.action;

import avicit.im.lantop.basic.archiveRecommendFolder.domain.ArchiveFolder;
import avicit.im.lantop.basic.archiveRecommendFolder.service.ArchiveRecommendFolderService;
import avicit.im.lantop.basic.archiveRecommendFolder.service.api.ArchiveRecommendFolderServiceApi;
import avicit.platform6.api.session.SessionHelper;
import avicit.platform6.core.context.ThreadContextHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @创建人 XMW
 * @创建时间: 2019/6/5
 * @描述:
 */
@RequestMapping("/archiveRecommendFolderController")
@Controller
public class ArchiveRecommendFolderController {


    @Autowired
    private ArchiveRecommendFolderServiceApi folderService;

    @RequestMapping("/saveFloder")
    @ResponseBody
    public Map<String, Object> saveFloder(HttpServletRequest request, String folderName, String sysId) {
        Map<String, Object> resultMap = new HashMap<>();
        String orgId = ThreadContextHelper.getOrgId();
        String deptId = ThreadContextHelper.getDeptId();
        String userId = SessionHelper.getLoginSysUserId(request);
        ArchiveFolder folder = new ArchiveFolder();
        folder.setOrgId(orgId);
        folder.setSysId(sysId);
        folder.setDeptId(deptId);
        folder.setCreatedBy(userId);
        folder.setFolderName(folderName);
        try {
            Integer integer = folderService.saveRecommendFolder(folder);
            resultMap.put("success", 1);
            resultMap.put("flag",integer);
        } catch (Exception e) {
            resultMap.put("success", 0);
        }
        return resultMap;
    }


    /**
     * @Author XMW
     * @Description: 获取推荐文件夹表格数据
     * @Param:
     * @Return:
     * @Create: 2019/6/5  15:53
     */
    @RequestMapping("/getRecommendFolderDatagrid")
    @ResponseBody
    public Map<String, Object> getRecommendFolderDatagrid(HttpServletRequest request, String sysId, Integer page, Integer rows) {
        Map<String, Object> recommendFolderDatagrid = folderService.getRecommendFolderDatagrid(ThreadContextHelper.getOrgId(), sysId, page, rows);
        return recommendFolderDatagrid;
    }


    /**
     * @Author XMW
     * @Description: 删除选中推荐文件夹
     * @Param:
     * @Return:
     * @Create: 2019/6/5  16:46
     */
    @RequestMapping("/delFloder")
    @ResponseBody
    public Map<String, Object> delFloder(String folderIds) {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            folderService.deleteRecommendFolder(folderIds);
            resultMap.put("success", 1);
        } catch (Exception e) {
            resultMap.put("success", 0);
        }
        return resultMap;
    }


    /**
     * @Author XMW
     * @Description: 删除选中推荐文件夹
     * @Param:
     * @Return:
     * @Create: 2019/6/5  16:46
     */
    @RequestMapping("/getRecommendFolder")
    @ResponseBody
    public List<ArchiveFolder> getRecommendFolder(HttpServletRequest request) {
        String orgId = ThreadContextHelper.getOrgId();
        List<ArchiveFolder> archiveFolderByOrgId = folderService.getArchiveFolderByOrgId(orgId);
        return archiveFolderByOrgId;
    }
}
